package cn.iocoder.yudao.server.framework.magicapi.config;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MagicApiWebConfig implements WebMvcConfigurer {

    @Getter
    @Value("${magic-ui.custom.resourceLocation:}")
    private String resourceLocation;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        if (StringUtils.isBlank(resourceLocation)) {
            return;
        }

        // 添加外部目录（绝对路径）
        registry.addResourceHandler("/**")
                .addResourceLocations(resourceLocation);
    }
}